﻿const express = require('express');
const app = express();
const PORT = 3000;
const path = require('path');

app.set('view engine', 'hbs');
app.set('views',path.join(__dirname,'views'));

const friendRouter = require("./routes/friends.router");
const messageRouter = require("./routes/messages.router");


app.use((req,res,next)=>{
    const start = Date.now();

   console.log(`${req.method} ${req.url}`);
   next();
   // actions go here...
    const delta = Date.now() - start;
    console.log(`${req.method} ${req.baseUrl} ${req.url} ${delta} ms`);
});


app.use('/site',express.static(path.join(__dirname,'public')));
app.use(express.json());

app.get('/',(req,res) =>{
    res.render('index',{
        title: 'My Friends are very clever',
        caption:'Let us go skiing'
    });
});

app.use('/friends',friendRouter);
app.use('/messages',messageRouter);


app.listen(PORT,()=>{
   console.log(`Listening on port ${PORT}...`);
});


